package com.hzw.saas.common.config.configuration;

import java.util.Date;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Value;

/**
 * mybatis 自动填充配置
 *
 * @author zzl
 * @since 05/10/2021
 */
// @Component
public class BaseMetaObjectHandler implements MetaObjectHandler {

    protected static final String DEFAULT_USER_ID = "system";

    // 逻辑未删除值
    @Value("${mybatis-plus.global-config.db-config.logic-not-delete-value:0}")
    protected int isNotDelete;

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "isDelete", Integer.class, isNotDelete);
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
    }


    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }

}
